package log

import (
	"gopkg.in/natefinch/lumberjack.v2"
	"log/slog"
	"time"
)

func Setup() {
	f1 := &lumberjack.Logger{
		Filename:   "./logs/stat_sphere.log",
		MaxSize:    10,    // megabytes
		MaxBackups: 10,    //
		MaxAge:     30,    // days
		Compress:   false, // disabled by default
	}

	slogOpt := &slog.HandlerOptions{
		AddSource: true,            // 记录日志位置
		Level:     slog.LevelDebug, // 设置日志级别
		ReplaceAttr: func(groups []string, a slog.Attr) slog.Attr {
			if a.Key == slog.TimeKey {
				a.Value = slog.StringValue(time.Now().Format(time.DateTime))
			}
			return a
		},
	}
	//
	l := slog.New(slog.NewTextHandler(f1, slogOpt))
	slog.SetDefault(l)
	slog.Warn("slog_complete_initialization")
}
